package com.psa.processor;

import com.psa.element.IJson;
import com.psa.element.RequestMessage;
import com.psa.element.UserElement;
import com.psa.tool.IGeneralEventCallback;
import com.psa.tool.IHttpCallback;

/**
 *
 * @author david
 * @date 2014-09-26
 */
public class LogoutProcessor implements IHttpCallback {
    private IGeneralEventCallback onGeneralEventListener;

    public void setOnGeneralEventListener(IGeneralEventCallback onGeneralEventListener) {
        this.onGeneralEventListener = onGeneralEventListener;
    }

    @Override
    public void callCompleted(RequestMessage message, IJson requestCmd) {
        UserElement userElement = (UserElement)requestCmd;
        triggerEvent(userElement.getSession());
    }

    @Override
    public void callError(RequestMessage message, String err) {
        triggerEvent(err);
    }

    private void triggerEvent(String msg){
        if (this.onGeneralEventListener!=null) {
            this.onGeneralEventListener.finished(this, msg);
        }
    }
}
